<template>
  <div>
    <!-- 重定向组件 - 用于刷新页面 -->
  </div>
</template>

<script setup>
import { onBeforeMount } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

onBeforeMount(() => {
  const currentPath = route.path
  const query = route.query
  
  // 处理时间戳查询参数，保留原始查询参数
  const queryParams = { ...query }
  if ('t' in queryParams) {
    delete queryParams.t
  }
  
  // 从路由路径中提取原始路径 /redirect/xxx => /xxx
  let targetPath = '/'
  
  if (currentPath.startsWith('/redirect')) {
    targetPath = currentPath.replace('/redirect', '')
    // 如果提取后为空，则使用首页
    if (!targetPath) {
      targetPath = '/'
    }
  }
  
  // 立即重定向到目标路径，保留原始查询参数
  router.replace({
    path: targetPath,
    query: Object.keys(queryParams).length > 0 ? queryParams : null
  })
})
</script> 